CC ?= gcc
TOPDIR =$(PWD)
BUILDDIR = $(TOPDIR)/build
OBJSDIR =$(BUILDDIR)/obj/
BINDIR =$(BUILDDIR)/bin
INCDIR =$(TOPDIR)/include
INCLUDES =$(foreach INCTREE,$(INCDIR),$(addprefix -I,$(INCTREE)))
SOURCEDIR = $(TOPDIR)/src\
			$(TOPDIR)/src/game_guess\
			$(TOPDIR)/src/game_click\
			$(TOPDIR)
OBJ=main.o \
	game_click.o \
	game_guess.o \
	display.o \
	core.o \
	carton.o \
	input_type.o \
	user.o \

$(shell test -d $(BUILDDIR) || mkdir $(BUILDDIR))
$(shell test -d $(BINDIR) || mkdir $(BINDIR))
$(shell test -d $(OBJSDIR) || mkdir $(OBJSDIR))

OBJS = $(foreach OBJTREE,$(OBJ),$(addprefix $(OBJSDIR)/,$(OBJTREE)))
		
ifeq ($(ver), debug)
	OUTPUTNAME := Debug_Game-Box
	CFLAGS ?=-g -Wall -O0 -D_DEBUG_
else
	OUTPUTNAME := Game-Box -MM
	CFLAGS ?=-Wall -O0 -MM
endif

vpath %.c $(SOURCEDIR)
vpath %.o $(OBJSDIR)

$(OUTPUTNAME):$(OBJ)
	$(CC) $(OBJS) -o $(BINDIR)/$@ $(CFLAGS)

%.o:%.c
	$(CC) $(INCLUDES) $(CFLAGS) -c $^ -o $(OBJSDIR)/$@

.PHONY: clean
clean:
	-rm -rf $(BUILDDIR) ./lib
